<template>
  <div class="systemButton">
    <CommonBtn label-name="按钮信息列表" :buttons="buttons" @onButtonClick="onButtonClick"></CommonBtn>
    <CommonList ref='list' :buttons="buttons" :columns="columns" :list-url="listUrl" :add="add" @tableSelect="tableSelect"></CommonList>
    <edit-pop-up  v-if="add" :out-btn="button" @refresh="conditionChange" :original-data="submit"
                  :props="add" @closeDialog="button=null" :submit-url="$api.API_RMBASE_OPERATION_ADD" :edit-url="$api.API_RMBASE_OPERATION_UPDATE"></edit-pop-up>
    <EnsurePopUp :out-btn="button" @close="button=null" @refresh="conditionChange" :original-data="row"
                 :delete-url="$api.API_RMBASE_OPERATION_DELETE"></EnsurePopUp>
    <IconSelector16 :show="show" @close="show =false" @select="handleSelect"></IconSelector16>
  </div>
</template>

<script>
  import CommonList from "../../common/CommonList"
  import CommonBtn from "../../common/CommonBtn";
  import EditPopUp from "../../common/EditPopUp";
  import EnsurePopUp from "../../common/EnsurePopUp";
  import IconSelector16 from "../../common/IconSelector16";
  export default {
      name:'todoList',
      data(){
        return{
            buttons:[
                this.$config.BTNS.ADD,
                this.$config.BTNS.EDIT,
                this.$config.BTNS.DELETE,
                this.$config.BTNS.HELP
            ],
            columns:[
                {
                    prop:'buttonImg',
                    label:'图标',
                    customSet(value) {
                        if (value) {
                            let src = "/static/img/16/"+value
                            return '<img src="'+src+'"/>'
                        }
                        return ""
                    },

                },
                {
                    prop:'buttonName',
                    label:'名称'
                },
                {
                    prop:'buttonType',
                    label:'位置'
                },
                {
                    prop:'buttonCode',
                    label:'事件'
                },
                {
                    prop:'sortCode',
                    label:'显示顺序',
                    minWidth:'60'
                },
                {
                    prop:'createUserName',
                    label:'创建用户'
                },
                {
                    prop:'createDate',
                    label:'创建时间'
                },
                {
                    prop:'modifyUserName',
                    label:'修改用户'
                },
                {
                    prop:'modifyDate',
                    label:'修改时间'
                },
                {
                    prop:'buttonRemak',
                    label:'说明'
                }
            ],
            add:{
                title:'菜单信息按钮',
                addItems:[
                    {name:'按钮名称',prop:'buttonName',type:'text'},
                    {name:'按钮标记',prop:'buttonTitle',type:'text'},
                    {name:'显示位置',prop:'buttonType',type:'select',options:[{label:'工具栏',value:'工具栏'}]},
                    {name:'菜单图标',prop:'buttonImg',type:'imgSelect',folder:'16',click:()=>{this.show=true}},
                    {name:'显示顺序',prop:'sortCode',type:'text'},
                    {name:'按钮事件',prop:'buttonCode',type:'textarea'},
                    {name:'说明',prop:'buttonRemak',type:'textarea'},
                ],
                type:'dialog'
            },
            listUrl:this.$api.API_RMBASE_OPERATION_LIST,
            button:{},
            row:{},
            show:false,
            submit:{}
        }
      },
      methods:{
          onButtonClick(item) {
              if (item.event == 'edit()'|| item.event == 'Delete()' ) {
                  if (!this.row || JSON.stringify(this.row) == '{}') {
                      this.$message.error("请选择一行数据")
                      return
                  }
                  this.submit = Object.assign({},this.row)
              }
              if (item.event == 'add()') {
                  this.submit = {}
              }
              this.button = item
          },
          tableSelect(row) {
              this.row = row
              this.$delete (this.row,'createDate')
              this.$delete (this.row,'modifyDate')
          },
          conditionChange() {
              this.row = null
              this.$refs.list.search()
          },
          handleSelect(img) {
              this.$set(this.submit,'buttonImg',img)
          }
      },
      components:{CommonList,CommonBtn,EditPopUp,EnsurePopUp,IconSelector16}
  }
</script>
